//
//  CallingListViewCell.m
//  CallTelphone
//
//  Created by mac on 2023/5/22.
//

#import "CallingListViewCell.h"
#import "Masonry.h"

@implementation CallingListViewCell

- (UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon6.png"]];
    }
    return _iconImageView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel){
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
        _nameLabel.text = @"张元武";
    }
    return _nameLabel;
}

- (UILabel *)addressLabel{
    if (!_addressLabel){
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.textColor = [UIColor lightGrayColor];
        _addressLabel.font = [UIFont systemFontOfSize:16];
        _addressLabel.text = @"住宅";
    }
    return _addressLabel;
}


- (UILabel *)timeLabel{
    if (!_timeLabel){
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.text = @"15:25";
    }
    return _timeLabel;
}

- (UIButton *)infoButton{
    if(!_infoButton){
        _infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_infoButton setImage:[UIImage imageNamed:@"icon8.png"] forState:UIControlStateNormal];
    }
    return _infoButton;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupViews];
        [self updateLayoutConstraints];
        [self bindViewModel];
    }
    return self;
}

- (void)bindViewModel{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setupViews{
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.addressLabel];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.infoButton];
}

- (void)updateLayoutConstraints{
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.iconImageView.mas_right);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(30);
        make.top.mas_equalTo(self.nameLabel.mas_top).offset(-5);
        make.left.mas_equalTo(self.contentView).offset(10);
    }];
    
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_equalTo(self.iconImageView.mas_right);
    }];
    
    [self.infoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(30);
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(self.contentView).offset(-17);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.infoButton.mas_left).offset(-10);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
}

@end
